package com.jxinternet.platform.services.util;

/**
 * Created by gold-jx on 2017/6/21.
 */
public class StringUtils {
    public static boolean isEmpty(String str) {
        return org.springframework.util.StringUtils.isEmpty(str);
    }
    public static boolean isEmpty(byte[] str) {
        return str.length==0;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    /**
     * 手机号取前3后4位 其他打*，如136****0055
     */
    public static String buildMobileString(String mobile) {

        String res = mobile.substring(0, 3) + "****" + mobile.substring(7, 11);
        return res;

    }

    public static String getNullToDefaultValue(String value, String defaultValue) {
        if (StringUtils.isEmpty(value)) {
            return defaultValue;
        }
        return value;
    }



    public static String getStringWithDefault(String value, String defaultStr) {
        if (StringUtils.isEmpty(value)) {
            return defaultStr;
        } else {
            return value;
        }
    }

    public static String StringUTF8(String str)  {
        try {
            str = new String(str.getBytes("gbk"),"utf-8");
            return str;
        }catch (Exception e){

        }

        return str;
    }
    public static String StringGBK(String str)  {
        try {
            str = new String(str.getBytes("utf-8"),"gbk");
            return str;
        }catch (Exception e){

        }

        return str;
    }


}